package com.scau.clothes.controller;

import com.scau.clothes.dao.OrderDao;
import com.scau.clothes.pojo.Order;
import com.scau.clothes.pojo.OrderClothes;
import com.scau.clothes.pojo.User;
import com.scau.clothes.service.CartService;
import com.scau.clothes.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class OrderController {
    @Autowired
    OrderDao orderDao;
    @Autowired
    OrderService orderService;
    @RequestMapping("createOrder")
    public ModelAndView createOrder(HttpServletRequest request){
        User user = (User) request.getAttribute("user");
        ModelAndView mv = new ModelAndView();
        int userId = user.getId();
        Order order = orderService.createOrderByUserId(userId);
        mv.addObject("order",order);
        mv.setViewName("order");
        return mv;
    }
    @RequestMapping("payOrder")
    public ModelAndView payOrder(HttpServletRequest request,int payType){
        User user = (User) request.getAttribute("user");
        int userId = user.getId();
        ModelAndView mv = new ModelAndView();
        orderService.payTheOrderByUserId(userId,payType);
        mv.setViewName("input");
        return mv;
    }
}
